//pack11jsclass

var UploadImagePopup = new uploadImagePopup();

function uploadImagePopup() {

    this.initialized=false;
    this.element=document.getElementById("PopupBody");
    this.form=document.getElementById("PopupBody");
    this.extra=document.getElementById("PopupBody");
    
    this.object=0;
    this.num=0;
    this.source="undefined";

    this.newPhoto = function(object,num) {
        UploadImagePopup.object=object;
        UploadImagePopup.num=num;
        PopupManager.open('UploadImagePopup');
    }

    this.open = function() {
        if(!this.initialized) this.init();
        if(!this.initialized) return;
        //this.form=document.getElementById("iupload");
        if(this.source=="undefined") this.source=this.form.src;
        newsrc=this.source.replace(/{object}/,this.object);
        newsrc=newsrc.replace(/{num}/,this.num);
        Trace(newsrc);
        this.form.src=newsrc;
        this.element.style.display="block";
        document.getElementById(PopupManager.container.id).style.display="block";
        PopupManager.currentPopup=this;
        PopupManager.popupActive=true;
    }

    this.init = function() {

        try {
            this.element=document.getElementById("UploadImagePopup");
            this.form=document.getElementById("iuploader");
        } catch(e) {
            alert("Could not find UploadImagePopup");
            return false;
        }

        if(this.element==null) {
            alert("Could not find UploadImagePopup");
            return false;
        }

        buttons=this.element.getElementsByTagName("input");
        for(tpb=0; tpb<buttons.length; tpb++) {
            button=buttons[tpb];
            if(button.id=="UploadImageSubmit") {
                button.onclick=this.submit;
            }

            if(button.id=="UploadImageCancel") {
                button.onclick=function() {
                PopupManager.close();
                }
            }
        }

        this.initialized=true;
    }

    this.submit = function() {
        var iframe;
        if (document.getElementById("iuploader").contentDocument){
            iframe=document.getElementById("iuploader").contentDocument;
        } else {
            iframe=document.frames["iuploader"].document;
        }
        iframe.getElementById("imgupload").submit();
        //document.frames["iuploader"].document.getElementById("imgupload").submit();
    }

    this.close = function(responseLine) {
        Trace("CLOSE: "+responseLine);
        PopupManager.close();
        var response=responseLine.split(" : ")[0];
        if(response=="error") return false;
        if(response=="delete") {
            image=document.getElementById("image_"+UploadImagePopup.object+"_"+UploadImagePopup.num);
            image.src="photos/small/noPhoto.gif";
            document.getElementById("image_"+UploadImagePopup.object+"_"+UploadImagePopup.num+"_name").value="";
        } else {
            image=document.getElementById("image_"+UploadImagePopup.object+"_"+UploadImagePopup.num);
            //image.src=null;
            image.src="photos/small/"+response+"?"+Math.random();
            document.getElementById("image_"+UploadImagePopup.object+"_"+UploadImagePopup.num+"_name").value=response;
        }
    }

    this.ajaxHandler = function(text,xml) {
        alert(text);
    }

    this.changeButton = function() {
        document.getElementById("UploadImageSubmit").value=document.getElementById("deletetosave").value;
    }

}